package month_04.day07;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class Demo2 {
    public static void main(String[] args) {
        System.out.println(System.currentTimeMillis());
        AtomicInteger count=new AtomicInteger(1);
        ScheduledExecutorService scheduledExecutorService= Executors.newScheduledThreadPool(10);
        scheduledExecutorService.scheduleAtFixedRate(
                ()->{
                    int currCount = count.getAndIncrement();
                    System.out.println(Thread.currentThread().getName());
                    System.out.println(System.currentTimeMillis() + "第" + currCount + "次" + "开始执行");
                    try {
                        TimeUnit.SECONDS.sleep(2);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(System.currentTimeMillis() + "第" + currCount + "次" + "执行结束");

                }
                ,1,1, TimeUnit.SECONDS);
    }
}
